library(devtools);
## Loading required package: usethis
path.github = "https://raw.githubusercontent.com/MonteShaffer/humanVerseWSU/master/";
source_url ( paste0( path.github, "humanVerseWSU/R/functions-colors.R" ) );
## SHA-1 hash of file is e57f8129df157979eac9eaf269071a8fb87cf546
http://md5.mshaffer.com/WSU_STATS419/_NOTEBOOKS_/
Here was a color tool I developed in 2007:
http://colors.mshaffer.com/?debug=monte
I tested it in the latest version of Chrome/Edge, still works …
grDevicesThere are several color options. The default colors are stored in the functions colors()
These are mostly x11 colors: https://en.wikipedia.org/wiki/X11_color_names
library(grDevices);
base.colors = colors();
colors.df = as.data.frame( cbind( (1:length(base.colors)), base.colors) );
colors.df;
displayColorOptions(base.colors);
rainbowThe code below generates 40 contiguous colors using the ?rainbow function. These values are hexadecimal RGB format https://www.w3schools.com/colors/colors_hexadecimal.asp.
colors.rainbow = rainbow(40, s = 0.6, v = 0.75);
displayColorOptions(colors.rainbow, ncol=4);
rainbowThe true RGB color has another element appended, “alpha transparency” also in hexadecimal form, providing a RGBa color https://www.w3schools.com/Css/css_colors_rgb.asp.
colors.rainbow = rainbow(40, s = 0.6, v = 0.75,
alpha=0.5);
displayColorOptions(colors.rainbow, ncol=4);
heat.colorsThe code below generates 40 contiguous colors using the ?heat.colors function.
colors.heat.colors = heat.colors(40);
displayColorOptions(colors.heat.colors, ncol=4);
heat.colorsThe code below generates 40 contiguous colors using the ?heat.colors function.
colors.heat.colors = heat.colors(40, alpha=0.5);
displayColorOptions(colors.heat.colors, ncol=4);
terrain.colorsThe code below generates 40 contiguous colors using the ?terrain.colors function.
colors.terrain.colors = terrain.colors(40);
displayColorOptions(colors.terrain.colors, ncol=4);
terrain.colorsThe code below generates 40 contiguous colors using the ?terrain.colors function.
colors.terrain.colors = terrain.colors(40, alpha=0.5);
displayColorOptions(colors.terrain.colors, ncol=4);
topo.colorsThe code below generates 40 contiguous colors using the ?topo.colors function.
colors.topo.colors = topo.colors(40);
displayColorOptions(colors.topo.colors, ncol=4);
topo.colorsThe code below generates 40 contiguous colors using the ?topo.colors function.
colors.topo.colors = topo.colors(40, alpha=0.5);
displayColorOptions(colors.topo.colors, ncol=4);
cm.colorsThe code below generates 40 contiguous colors using the ?cm.colors function.
colors.cm.colors = cm.colors(40);
displayColorOptions(colors.cm.colors, ncol=4);
cm.colorsThe code below generates 40 contiguous colors using the ?cm.colors function.
colors.cm.colors = cm.colors(40, alpha=0.5);
displayColorOptions(colors.cm.colors, ncol=4);
hcl.colorshcl.palette.list = hcl.pals();
as.data.frame( hcl.palette.list );
for(i in 1:length(hcl.palette.list))
{
hcl = hcl.palette.list[i];
colors.hcl.colors = hcl.colors(40, palette=hcl);
print(paste0("Palette: ", hcl));
displayColorOptions(colors.hcl.colors, ncol=4);
print(paste0(" ---> alpha: ", 0.5));
colors.hcl.colors = hcl.colors(40, palette=hcl,
alpha=0.5);
displayColorOptions(colors.hcl.colors, ncol=4);
}
## [1] "Palette: Pastel 1"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Dark 2"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Dark 3"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Set 2"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Set 3"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Warm"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Cold"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Harmonic"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Dynamic"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Grays"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Light Grays"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Blues 2"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Blues 3"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Purples 2"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Purples 3"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Reds 2"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Reds 3"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Greens 2"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Greens 3"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Oslo"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Purple-Blue"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Red-Purple"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Red-Blue"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Purple-Orange"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Purple-Yellow"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Blue-Yellow"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Green-Yellow"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Red-Yellow"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Heat"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Heat 2"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Terrain"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Terrain 2"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Viridis"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Plasma"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Inferno"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Dark Mint"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Mint"
## [1] " ---> alpha: 0.5"
## [1] "Palette: BluGrn"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Teal"
## [1] " ---> alpha: 0.5"
## [1] "Palette: TealGrn"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Emrld"
## [1] " ---> alpha: 0.5"
## [1] "Palette: BluYl"
## [1] " ---> alpha: 0.5"
## [1] "Palette: ag_GrnYl"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Peach"
## [1] " ---> alpha: 0.5"
## [1] "Palette: PinkYl"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Burg"
## [1] " ---> alpha: 0.5"
## [1] "Palette: BurgYl"
## [1] " ---> alpha: 0.5"
## [1] "Palette: RedOr"
## [1] " ---> alpha: 0.5"
## [1] "Palette: OrYel"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Purp"
## [1] " ---> alpha: 0.5"
## [1] "Palette: PurpOr"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Sunset"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Magenta"
## [1] " ---> alpha: 0.5"
## [1] "Palette: SunsetDark"
## [1] " ---> alpha: 0.5"
## [1] "Palette: ag_Sunset"
## [1] " ---> alpha: 0.5"
## [1] "Palette: BrwnYl"
## [1] " ---> alpha: 0.5"
## [1] "Palette: YlOrRd"
## [1] " ---> alpha: 0.5"
## [1] "Palette: YlOrBr"
## [1] " ---> alpha: 0.5"
## [1] "Palette: OrRd"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Oranges"
## [1] " ---> alpha: 0.5"
## [1] "Palette: YlGn"
## [1] " ---> alpha: 0.5"
## [1] "Palette: YlGnBu"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Reds"
## [1] " ---> alpha: 0.5"
## [1] "Palette: RdPu"
## [1] " ---> alpha: 0.5"
## [1] "Palette: PuRd"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Purples"
## [1] " ---> alpha: 0.5"
## [1] "Palette: PuBuGn"
## [1] " ---> alpha: 0.5"
## [1] "Palette: PuBu"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Greens"
## [1] " ---> alpha: 0.5"
## [1] "Palette: BuGn"
## [1] " ---> alpha: 0.5"
## [1] "Palette: GnBu"
## [1] " ---> alpha: 0.5"
## [1] "Palette: BuPu"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Blues"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Lajolla"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Turku"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Blue-Red"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Blue-Red 2"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Blue-Red 3"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Red-Green"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Purple-Green"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Purple-Brown"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Green-Brown"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Blue-Yellow 2"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Blue-Yellow 3"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Green-Orange"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Cyan-Magenta"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Tropic"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Broc"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Cork"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Vik"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Berlin"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Lisbon"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Tofino"
## [1] " ---> alpha: 0.5"
## [1] "Palette: ArmyRose"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Earth"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Fall"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Geyser"
## [1] " ---> alpha: 0.5"
## [1] "Palette: TealRose"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Temps"
## [1] " ---> alpha: 0.5"
## [1] "Palette: PuOr"
## [1] " ---> alpha: 0.5"
## [1] "Palette: RdBu"
## [1] " ---> alpha: 0.5"
## [1] "Palette: RdGy"
## [1] " ---> alpha: 0.5"
## [1] "Palette: PiYG"
## [1] " ---> alpha: 0.5"
## [1] "Palette: PRGn"
## [1] " ---> alpha: 0.5"
## [1] "Palette: BrBG"
## [1] " ---> alpha: 0.5"
## [1] "Palette: RdYlBu"
## [1] " ---> alpha: 0.5"
## [1] "Palette: RdYlGn"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Spectral"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Zissou 1"
## [1] " ---> alpha: 0.5"
## [1] "Palette: Cividis"
## [1] " ---> alpha: 0.5"
colorRampPaletteYou can interpolate a color gradient as well.
colvec=c("red","royalblue");
my.colors = colorsInGradient(40, colvec, FALSE);
displayColorOptions(my.colors, ncol=4);
colvec=c("red","royalblue","seagreen");
my.colors = colorsInGradient(40, colvec, FALSE);
displayColorOptions(my.colors, ncol=4);
I wrote a few helper functions to manipulate and store colors.
displayColorOptions to display these rectangular summaries of colors. If rendered as HTML, it would be more useful, as you could copy/paste the code. I will work on that option.
colorsInGradient is a wrapper for the odd-structured function colorRampPalette
There is a built-in col2rgb function that was missing its reciprocal or inverse, so I wrote it as rgb2col
col2rgb("red"); and rgb2col( col2rgb("red") ); … useful for grabbing the HEX color scheme from the named scheme
indexColors builds the index and searchColor can do a lookup based on name (which is unique) or based on hex (which is not necessarily unique, so may return multiple values). I may use a multi-dimensional distance metric to compute a “fuzzyColorSearch” calling it findNearestColorOnline, you can read about all these special/cool palettes developed by others libraries (e.g., “RColorBrewer” or “wesanderson”). There is nothing new or novel in these libraries. RGB and specifically RGBa are how colors are built in R (and in most user interfaces). You can do some research, and build your own palette using the information contained herein. The “pretty colors” are often a function of an “alpha” level of RGBa. And it is related to the psychological perceptions we have as to why the color is “pretty”.
# build a custom palette ...
# https://brand.wsu.edu/visual/colors/
colors.list = list();
colors.list[["monte_shaffer@wsu.edu"]] = list();
colors.list[["monte_shaffer@wsu.edu"]][["crimson"]] = "#981e32";
colors.list[["monte_shaffer@wsu.edu"]][["crimson-accent"]] = "#c60c30";
colors.list[["monte_shaffer@wsu.edu"]][["gray"]] = "#5e6a71";
colors.list[["monte_shaffer@wsu.edu"]][["gray-darker1"]] = "#464e54";
colors.list[["monte_shaffer@wsu.edu"]][["gray-darker2"]] = "#2a3033";
colors.list[["monte_shaffer@wsu.edu"]][["gray-black"]] = "#000000";
colors.list[["monte_shaffer@wsu.edu"]][["gray-lighter1"]] = "#8d959a";
colors.list[["monte_shaffer@wsu.edu"]][["gray-lighter2"]] = "#b5babe";
colors.list[["monte_shaffer@wsu.edu"]][["gray-lighter3"]] = "#d7dadb";
colors.list[["monte_shaffer@wsu.edu"]][["gray-lighter4"]] = "#eff0f1";
colors.list[["monte_shaffer@wsu.edu"]][["gray-white"]] = "#FFFFFF";
colors.list[["monte_shaffer@wsu.edu"]][["gray-lighter1"]] = "#8d959a";
colors.list[["monte_shaffer@wsu.edu"]][["orange"]] = "#b67233";
colors.list[["monte_shaffer@wsu.edu"]][["orange-accent"]] = "#f6861f";
colors.list[["monte_shaffer@wsu.edu"]][["green"]] = "#8f7e35";
colors.list[["monte_shaffer@wsu.edu"]][["green-accent"]] = "#ada400";
colors.list[["monte_shaffer@wsu.edu"]][["blue"]] = "#4f868e";
colors.list[["monte_shaffer@wsu.edu"]][["blue-accent"]] = "#00a5bd";
colors.list[["monte_shaffer@wsu.edu"]][["yellow"]] = "#c69214";
colors.list[["monte_shaffer@wsu.edu"]][["yellow-accent"]] = "#ffb81c";
# to practice, build out your own color scheme ...
mycolors = unlist(colors.list$`monte_shaffer@wsu.edu`);
displayColorOptions(mycolors, showHEX=TRUE, ncol=2);
When you play with RGB addressable lights in electronics, you can get two types, RGB and RGBw. The ability to create mixture of light by having 3 or 4 small LEDs light up is the basic function of how light emission works. Here is a short video clip https://www.youtube.com/watch?v=DBRJ0KbI1Hk of an application, which was programmed in embedded C as part of a research grant to develop automated technologies to engage the mind and body of persons with Parkinson’s disease https://www.nsf.gov/awardsearch/showAward?AWD_ID=1819997. [We also had a nice punch-detection algorithm that would use the statistic called MAD to perform real-time signal processing. I will likely document some of that algorithm in a “mastery” notebook.]
Obviously, the color schema presented herein is a function of light emission (which is how computers operate) and the aesthetics would be different for a paint-schema for color, as that is a function of how light reflects off a tangible surface.